<%@ include file="css/header.jsp" %>
<title>RD Billing</title>
<%
String userId;
String rdBilling;
if((String)session.getAttribute("userId")==null||((String)session.getAttribute("userId")).trim().length() == 0) userId = "null";
else userId = (String)session.getAttribute("userId");
if((String)session.getAttribute("rdBilling")==null||((String)session.getAttribute("rdBilling")).trim().length() == 0) rdBilling = "null";
else rdBilling = (String)session.getAttribute("rdBilling");
	if(!(userId.equals("null"))){
		if(rdBilling.equals("1")){
%>
<script type="text/javascript">
	var jqueryOption = {};
	jqueryOption.grdRowNum = 50;
	jqueryOption.grdRowList = [50, 100, 200];
	jqueryOption.grdJsonReader = {
	    root: "rows",
	    page: "page",
	    total: "total",
	    records: "records",
	    repeatitems: true, //if 'false' will chage json reader format to 'name' require
	    //cell: "cell",
	    id: "0" //id: "id"
	};
	var RDBilling= new (function() {
        /**
         * Page Function
         */
        this.doError = function ()  {
            $.msgbox('Load Failed', {
                type : 'error'
            }, function(buttonPressed) {
            	//window.location.href = "index.html";
            });
        };

        this.bindgrdTransaction = function (ipage){
            var formObj = $("#formRDBilling");
            var strUrl = formObj.serialize();
            $("#grdRDBilling").jqGrid('setGridParam'
                    ,{url:"<%=request.getContextPath()%>/RDBilling/BindGrdRDBilling"
                            +"?" + strUrl
                        ,page: ipage}).trigger("reloadGrid");
        };
    })();

	
    

$(document).ready(function() {

	var ratePerTransaction = <%=request.getAttribute("ratePerTransactionRd")%>;
	$('#mnu li').hover(
	        function () {
	            //show its submenu
	            $('ul', this).slideDown(100);
	 
	        }, 
	        function () {
	            //hide its submenu
	            $('ul', this).slideUp(100);         
	        }
	    );
	
    	$("#btnCalculate").click(function(){
    		RDBilling.bindgrdTransaction(1);
            return false;
        });
    	
	var grdObj = $("#grdRDBilling");
        grdObj.jqGrid({
        	datatype: 'json',
            mtype: 'POST',
            colNames:['Date','Amount',],
            colModel:[
                {name:'date', index:'date',width:70,align:'center', sortable:false},
                {name:'amount', index:'amount',title:false, width:30, align:'center',sortable:false}
            ],
            postData: {
            },
            rowNum: jqueryOption.grdRowNum, //50
            rowList: jqueryOption.grdRowList, //[50, 100, 200]
            autowidth: true, //Equal Container !Not change when resize window
            height: -1, //Auto height
            scrollOffset: 1, //Hide scroll bar
            pager: '#pagerRDBilling',
            rownumbers: true,
            viewrecords: true,
            sortname: '',
            sortorder: "desc",
            cache: false,
            caption: 'RD Billing',
            emptyrecords: 'No result',
            jsonReader : jqueryOption.grdJsonReader,
            onPaging: function(pgButton){ //pgButton : check which button click
            	//TrackViewer.bindgrdTransaction($("#grdTCDBilling").getGridParam('page'));
            },
            onSortCol: function(index, iCol, sortorder){
            	//TrackViewer.bindgrdTransaction($("#grdTCDBilling").getGridParam('page'));
            },
            loadError: function(xhr, status, error) {
            	//TrackViewer.doError();
            },
            loadComplete: function(data) {
                if (data != null){
                    var txtTransaction = "Total transaction";
	                var transaction =  data.transaction+" Transactions";
	                var txtCost = "Total cost";
	                var cost =   (data.transaction*ratePerTransaction)+" Baht";
	                $("#txtTransactions").text(txtTransaction);
	                $("#transactions").text(transaction);
	                $("#txtCost").text(txtCost);
	                $("#cost").text(cost);
	                try {
	 					if(data.error != null){
	 	                	$.msgbox(data.error, {
	 	                        type : 'error'
	 	                    }, function(buttonPressed) {
	 	                    
	 	                    });
	 					}
	 				} catch (e) {
	 					
	 				}
                }

               
              
            },
            gridComplete: function() {
                
            }
        });
    });

</script>
<body>
<div id="jp-main">
        <div class="jp-sheet">
            <div class="jp-sheet-tl"></div>
            <div class="jp-sheet-tr"></div>
            <div class="jp-sheet-bl"></div>
            <div class="jp-sheet-br"></div>
            <div class="jp-sheet-tc"></div>
            <div class="jp-sheet-bc"></div>
            <div class="jp-sheet-cl"></div>
            <div class="jp-sheet-cr"></div>
            <div class="jp-sheet-cc"></div>
            <div class="jp-sheet-body">
                <div class="jp-header">
                    <div class="jp-header-center">
                        <div class="jp-header-png"></div>
                        <div class="jp-header-jpeg"></div>
                    </div>
                        <div class="jp-header-fluid-object"></div>
                </div>
                <div class="jp-nav">
                	<div class="l"></div>
                	<div class="r"></div>
                	<ul class="jp-menu">
                		
                			<%if (session.getAttribute("tcdTracking").equals("1")){%>
					    	  <li>
					    	  	<a href="ViewServlet"><span class="l"></span><span class="r"></span><span class="t">TCD Tracking</span></a>                		
                			  </li>
					      	<%} %>
					      	<%if (session.getAttribute("rdTracking").equals("1")){%>
					    	  <li>
					    	  	<a href="ViewServletRD"><span class="l"></span><span class="r"></span><span class="t"></span><span class="t">RD Tracking</span></a>                		
                			  </li>
					      	<%} %>
					      	<%if (session.getAttribute("tcdBilling").equals("1")){%>
					    	  <li>
					    	  					    	  	<a href="TCDBillingServlet"><span class="l"></span><span class="r"></span><span class="t"></span><span class="t">TCD Billing</span></a>                		
					    	                  			  </li>
					      	<%} %>
					      	<%if (session.getAttribute("rdBilling").equals("1")){%>
					    	  <li>
					    	  	<a href="RDBilling" class="active"><span class="l"></span><span class="r"></span><span class="t"></span><span class="t">RD Billing</span></a>                		              		
                			  </li>
					      	<%} %>
					      	<%if (!(userId.equals("0"))){%>
					    	  <li>
					    	  	<a href="EditProfile.jsp"><span class="l"></span><span class="r"></span><span class="t"></span><span class="t">Edit profile</span></a>                		
                			  </li>
					      	<%} %>
                			
           		  		<li>
                			<a href="#"><span class="l"></span><span class="r"></span><span class="t">User Management</span></a>
							<ul>
								<%if (session.getAttribute("manageUsers").equals("1")){%>
						    		<li><a href="ManageAdminServlet">Manage users</a></li>
						      	<%} %>
						      	<%if (session.getAttribute("manageGroups").equals("1")){%>
					    			<li><a href="ManageGroupServlet">Manage groups</a></li>
					      		<%} %>
					      		<%if (session.getAttribute("userLog").equals("1")){%>
					    			<li><a href="UserLogServlet">User log</a></li>
					      		<%} %>
           					</ul>
               		  	</li>		
           		  	  	<li>
                			<a href="Logout"><span class="l"></span><span class="r"></span><span class="t">Logout</span></a>                		
                	  	</li>
               	  </ul>
                </div>
                <div class="jp-content-layout">
                  <div class="jp-post-body">
                     <h2 class="jp-postheader">RD Billing</h2>
                      <div class="jp-postcontent">
                      <div id="TCDBilling">
                      <script>
							$(function() {
								$("#fromTime").datepicker({
									dateFormat: 'yy-mm-dd'
								});
							});
							$(function() {
								$("#toTime").datepicker({
									dateFormat: 'yy-mm-dd'
								});
							});
						</script>
                             <fieldset id="fsRDBilling">
			            <legend class="pageTitleSearch"><h3>RD Search form</h3></legend>
			            <form id="formRDBilling" method="POST" class="form" >
			                <fieldset>
			                    <ol>
			                    	<li class="">
			                            <div class="colTile">
			                              <label for="txtDate">Date</label>
			                            </div>
			                            <div class="colContent">
			                                 Start Date : <input type="text" name="fromTime" id="fromTime" value="" /> End Date : <input type="text" name="toTime" id="toTime" value="" /><br/>
			                            </div>
			                        </li>
			                      
			                        <li>
			                            <div  class="colTile">
			                                &nbsp;
			                            </div>
			                            <div class="colContent">
			                                <div id="btnCommand">
			                                  <button id="btnClear" type="reset" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary"><span class="ui-button-icon-primary ui-icon ui-icon-refresh"></span><span class="ui-button-text">Clear</span></button>
			                                   <button id="btnCalculate" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-icon-primary" ><span class="ui-button-icon-primary ui-icon ui-icon-pencil"></span><span class="ui-button-text">Calculate</span></button>
			                                </div>
			                            </div>
			                        </li>
			                        <li class="">
			                            <div class="colTile">
			                            <div><label for="txtDate">Cost per transaction</label></div>
			                            <div><label id = "txtTransactions" for="txtDate"></label></div>
			                              <div><label id= "txtCost" for="txtDate"></label></div>
			                            </div>
			                            <div class="colContent">
			                            <div><label><%=request.getAttribute("ratePerTransactionRd")%> Baht</label></div>
			                            <div><label id = "transactions"></label></div>
			                               <div><label id ="cost"></label></div>
			                            </div>
			                        </li>
			                    </ol>
			                </fieldset>
			            </form>
                            <div id="content-placeholder">
                                <div id="jqgrid">
                                    <table id="grdRDBilling"></table>
                                    <div id="pagerRDBilling"></div>
                                </div>
                            </div>
			        	</fieldset>            
			        	</div>
                      </div>
                  </div>
                </div>
            </div>
        </div>
</div>
    
</body>	
<%
		}else{
%>
<script type="text/javascript">
    	window.location.href = "EditProfile";
</script>
<%
		}
	}else{
%>
<script type="text/javascript">
	window.location.href = "LoginServlet";
</script>
<%
	}
	
%>
</html>